package geppetto.reordering;

import java.util.LinkedList;
import java.util.List;

import geppetto.cat.alignments.AlignmentsSet;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePair;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.SentenceInfo;
import geppetto.phraseScorer.AbstractPhraseScorer;
import geppetto.phraseScorer.WeightedPhraseScorerPhraseScorer;
import geppetto.reordering.graph.GraphWeightScorer;
import geppetto.reordering.graph.ReorderingGraph;

public class WeightedGraphPhraseReorderingCalculator  extends GraphPhraseReorderingCalculator{
	List<GraphWeightScorer> scorers = new LinkedList<GraphWeightScorer>();

	public WeightedGraphPhraseReorderingCalculator(AlignmentsSet set) {
		super(set);
	}

	public void addGraphScorer(GraphWeightScorer scorer){
		scorers.add(scorer);
	}

	@Override
	protected ReorderingGraph getReorderingGraph(SentenceInfo senInfo) {
		ReorderingGraph graph = new ReorderingGraph(senInfo);
		graph.setScorer(new GraphWeightScorer() {

			@Override
			public double scoreNextArc(ExtractedPhrasePair from,
					ExtractedPhrasePair to) {
				double score = 1d;
				for(GraphWeightScorer s : scorers){
					score*=s.scoreNextArc(from, to);
				}
				return score;
			}

			@Override
			public double scorePrevArc(ExtractedPhrasePair from,
					ExtractedPhrasePair to) {
				double score = 1d;
				for(GraphWeightScorer s : scorers){
					score*=s.scorePrevArc(from, to);
				}
				return score;
			}
			
			@Override
			public double scoreNode(ExtractedPhrasePair node) {
				double score = 1d;
				for(GraphWeightScorer s : scorers){
					score*=s.scoreNode(node);
				}
				return score;
			}
		});
		graph.generateWeightedGraphPaths();
		return graph;
	}


}